﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="format-detection" content="telephone=no, email=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <title>Title</title>
</head>
<body>
<h6>内容在控制台</h6>
<script>
    //
    //数组去重 2种方法
    //数组排序 2种方法


    //   数组去重
    var arr = [1, 2, 3, 1, "a", 5, 7, "a", "b", 4, 4, 16, 9];
    function one(aee) {
        let arr2 = [];
        let flag;
        for (let i = 0; i < arr.length; i++) {
            flag = false;
            for (let j = i + 1; j < arr.length; j++) {
                if (arr[i] == arr[j]) {
                    flag = true
                }
            }
            if (!flag) {
                arr2.push(arr[i])
            }
        }
        return arr2
    }
    console.log(arr)
    console.log(one(arr))

    function two() {
        let arr2 = [];
        arr.sort();
        for (let i = 0; i < arr.length; i++) {
            if (arr[i] != arr[i + 1]) {
                arr2.push(arr[i])
            }
        }
        return arr2
    }
    console.log(two(arr))

    //    数组排序
    var arr0 = [1, 2, 53, 5, 8, 4, 9, 10, 13, 104, 0, 3, 6];
    function seq(arr) {
        /*给每个未确定的位置做循环*/
        for (let j = arr.length - 1; j > 0; j--) {
            /*给进度做个记录，比到未确定位置*/
            for (let i = 0; i < j; i++) {
                if (arr[i] > arr[i + 1]) {
                    let temp = arr[i];
                    arr.splice(i, 1, arr[i + 1]);
                    arr.splice(i + 1, 1, temp);
                }
            }
        }
        return arr;
    }
    console.log(seq(arr0))

    arr0.sort(function (a,b) {
        return a-b
    })
    console.log(arr0)

</script>
</body>
</html>